package com.atguigu.yygh.Controller.api;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.service.DepartmentService;
import com.atguigu.yygh.service.HospitalService;
import com.atguigu.yygh.service.HospitalSetService;
import com.atguigu.yygh.service.ScheduleService;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.atguigu.yygh.vo.hosp.ScheduleOrderVo;
import com.atguigu.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @description: TODO
 * @author: 化一帆
 * @date: 2022/12/2 16:30
 * @version: v1.0
 */
@Api(tags = "用户前台接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospApiController {
    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @Autowired
    private HospitalSetService hospitalSetService;

    /**
     * @description:  查询医院的列表功能
     * @author 化一帆
     * @date 2022/12/2 16:33
     */
    @ApiOperation("查询医院的列表功能")
    @GetMapping("findHospList/{page}/{limit}")
    public R findHospList(@PathVariable Integer page,
                          @PathVariable Integer limit,
                          HospitalQueryVo hospitalQueryVo){
        Page<Hospital> hospitals = hospitalService.selectHospitalPage(page, limit, hospitalQueryVo);
        return R.ok().data("pages",hospitals);
    }

    /**
     * @description:  根据医院名称进行模糊查询
     * @author 化一帆
     * @date 2022/12/2 16:42
     */
    @ApiOperation(value = "根据医院名称查询")
    @GetMapping("findByHosname/{hosname}")
    public R findByHosname(@PathVariable String hosname){
      List<Hospital> list=  hospitalService.findByHosname(hosname);
      return R.ok().data("list",list);
    }

    /**
     * @description: 根据医院的编号查询所有的科室的信息
     * @author 化一帆
     * @date 2022/12/2 18:49
     */
    @ApiOperation(value = "根据医院的编号回去所有的科室的信息,返回所有的科室")
    @GetMapping("department/{hoscode}")
    public R index(@PathVariable String hoscode){
        List<DepartmentVo> deptTree = departmentService.findDeptTree(hoscode);
        return R.ok().data("list",deptTree);
    }

    /**
     * @description: 根据医院的编号获取科室的预约挂号详情信息
     * @author 化一帆
     * @date 2022/12/2 18:56
     */
    @ApiOperation(value = "根据医院的编号获取科室的预约挂号详情信息")
    @GetMapping("findHospDetail/{hoscode}")
    public R item(@PathVariable String hoscode){
        Map<String,Object> map=hospitalService.item(hoscode);
        return R.ok().data(map);
    }

    /**
     * @description: 获取可预约的排班数据
     * 根据医院的编号和小科室的编号获取盘般的数据，并进行分页展示
     * @author 化一帆
     * @date 2022/12/7 19:49
     */
    //日期列表
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public R getBookingSchedule(@PathVariable Integer page, @PathVariable Integer limit,
                                @PathVariable String hoscode,@PathVariable String depcode) {

        Map<String, Object> map = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return R.ok().data(map);
    }
    /**
     * @description: 根据医院编号+科室编号+日期  查询排班列表
     * 通过医院的编号和科室编号以及排班日期
     * @author 化一帆
     * @date 2022/12/7 19:50
     */
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public R findScheduleList(@PathVariable String hoscode,@PathVariable String depcode,@PathVariable String workDate) {
        List<Schedule> scheduleList = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return R.ok().data("scheduleList",scheduleList);
    }

    /**
     * @description: 根据排班的id获取排班的数据
     * 前端传过来当前医生排班的id
     * @author 化一帆
     * @date 2022/12/8 16:37
     */
    @GetMapping("getSchedule/{id}")
    public R getSchedule(@PathVariable String id){
        Schedule schedule=scheduleService.getById(id);
        return R.ok().data("schedule",schedule);
    }

    /**
     * @description: 根据排班id获取预约下单数据
     * @author 化一帆
     * @date 2022/12/8 18:59
     */

    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    /**
     * @description: 根据医院编号获取医院设置对象的签名信息
     * @author 化一帆
     * @date 2022/12/8 19:25
     */
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable("hoscode") String hoscode) {
        return hospitalSetService.getSignInfoVo(hoscode);
    }
}
